const fnMap = {};

const useBeforeSubmit = tag => {
    const setHandler = fn => {
        fnMap[tag] = fn;
    };
    const handleBeforeSubmit = values => {
        const fn = fnMap[tag];
        if (!fn) return values;
        try {
            return fn(values);
        } catch (e) {
            console.error(e);
            return values;
        }
    };
    return {
        setHandler,
        handleBeforeSubmit
    };
};

export default useBeforeSubmit;
